package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.StudentAchievement;
import com.wuseguang.springcloud.service.StudentAchievementService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/achievement")
public class StudentAchievementController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private StudentAchievementService service;

    /**
     * @描述 添加成绩管理
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/addSchoolAchievement")
    public Result addSchoolAchievement(RequestParameterWrapper request,
                                       @RequestParam(value = "list") String list,
                                       @RequestParam(value = "name") String name,
                                       @RequestParam(value = "type") Integer type) {
        String schoolId = request.getParam("schoolId");
        String termId = request.getParam("termId");
        String teacherId = request.getParam("teacherId");
        logger.info("addSchoolAchievement,schoolId={},termId={},teacherId={},name={}", schoolId, termId, teacherId, name);
        return service.addSchoolAchievement(schoolId, termId, list, name, teacherId, type);
    }

    /**
     * @描述 组合查询成绩单列表
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/querySchoolAchievement")
    public Result querySchoolAchievement(RequestParameterWrapper request,
                                         @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                         @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows,
                                         @RequestParam(value = "name", required = false) String name,
                                         @RequestParam(value = "sStime", required = false) String sStime,
                                         @RequestParam(value = "eStime", required = false) String eStime) {
        String schoolId = request.getParam("schoolId");
        String termId = request.getParam("termId");
        String teacherId = request.getParam("teacherId");
        String admin = request.getParam("admin");
        logger.info("addSchoolAchievement,schoolId={},termId={},name={}", schoolId, termId, name);
        return service.querySchoolAchievement(schoolId, termId, name, indexNo, rows, teacherId, admin,sStime,eStime);
    }

    /**
     * @描述 删除成绩列表
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/delSchoolAchievement")
    public Result delSchoolAchievement(RequestParameterWrapper request, @RequestParam(value = "id") Integer id) {
        String teacherId = request.getParam("teacherId");
        return service.delSchoolAchievement(id, teacherId);
    }

    /**
     * @描述 根据成绩管理id查询详情
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/querySchoolAchievementById")
    public Result querySchoolAchievementById(@RequestParam(value = "id") Integer id) {
        return service.querySchoolAchievementById(id);
    }


    /**
     * @描述 自动填充学生姓名
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/updateAchievementStudent")
    public Result updateAchievementStudent(@RequestParam(value = "id") Integer id,
                                           @RequestParam(value = "classId") String classId) {//该成绩对应的id
        return service.updateAchievementStudent(id, classId);
    }

    /**
     * @描述 根据id查询所有相关科目，且未被添加的科目
     * @创建人 zm
     * @创建时间 2020/4/16
     */
    @RequestMapping("/queryCourseList")
    public Result queryCourseList(@RequestParam(value = "id") Integer id) {//该成绩对应的id
        return service.queryCourseList(id);
    }


    /**
     * @描述 查询所有科目接口
     * @创建人 zm
     * @创建时间 2020/4/17
     */
    @RequestMapping("/querySubjectsAll")
    public Result querySubjectsAll(RequestParameterWrapper request) {
        String schoolId = request.getParam("schoolId");
        logger.info("querySubjects->schoolId={}", schoolId);
        return new Result(service.querySubjectsAll(schoolId));
    }

    /**
     * @描述 添加科目和删除科目
     * @创建人 zm
     * @创建时间 2020/4/17
     */
    @RequestMapping("/updateAchievementCourse")
    public Result updateAchievementCourse(@RequestParam(value = "id") Integer id, @RequestParam(value = "total_score") String total_score, @RequestParam(value = "state") Integer state) {
        return service.updateAchievementCourse(id, total_score, state);
    }

    /**
     * @描述 学生成绩统计
     * @创建人 zm
     * @创建时间 2020/4/17
     */
    @RequestMapping("/queryScoreStatistics")
    public Result queryScoreStatistics(@RequestParam(value = "id") Integer id) {
        logger.info("queryScoreStatistics,id={}", id);
        return service.queryScoreStatistics(id);
    }


    /**
     * @描述 成绩发送给家长
     * @创建人 zm
     * @创建时间 2020/4/21
     */
    @RequestMapping("/sendParent")
    public Result sendParent(@RequestParam(value = "id") Integer id) {
        logger.info("sendParent,id={}", id);
        return service.sendParent(id);
    }

    /**
     * @描述 批量添加成绩
     * @创建人 zm
     * @创建时间 2020/4/21
     */
    @RequestMapping("/batchAdditionAchievement")
    public Result batchAdditionAchievement(@RequestParam(value = "list") String list, @RequestParam(value = "id") Integer id) {
        return service.batchAdditionAchievement(list, id);
    }


    /**
     * @描述 导出成绩模板
     * @创建人 zm
     * @创建时间 2020/4/17
     */
    @RequestMapping("/exportAchievement")
    public void exportAchievement(RequestParameterWrapper request, HttpServletResponse response, @RequestParam(value = "id") Integer id,
                                  @RequestParam(value = "type", required = false, defaultValue = "0") Integer type) {
        logger.info("导出成绩模板信息");
        service.exportAchievement(request, response, id, type);
    }

}
